package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.FP;
	/**
	 * © 2012 TheJavaArcade.com
	 */	
	public class Worm extends Entity {
		private var wormSprite:Spritemap = new Spritemap(Assets.WORM_SPRITE, 16, 16);
		public var level:int;
		public var state:int;
		
		public function Worm(theLevel:int) {
			level = theLevel;
			state = 0;
			wormSprite.add("fly", [0,1,2,3,2,1], 5, true);
			graphic = wormSprite;
			wormSprite.play("fly");
			type = "worm";
			setHitbox(48, 48, 16, 16);
			layer = 1;
			var dataList:XMLList;
			var dataElement:XML;
			dataList = GameEngine.levelXML[theLevel].bugs.worm;
			for each(dataElement in dataList) {
				x = dataElement.@x;
				y = dataElement.@y;
			}
		}
		override public function update():void {
			if (GameEngine.level == level && collide("fracas", x , y)) {
				if (state == 0) {
					GameEngine.wormDialogue.theText.text = "Please take this file to our double agent, the Moth.\nYou will be rewarded.";
					GameEngine.wormDialogue.y = y - 25;
					GameEngine.file.x = x - 50;
					GameEngine.file.y = y;
					GameEngine.file.state = 1;
					GameEngine.file.visible = true;
				}
				if (state == 1) {
					GameEngine.wormDialogue.theText.text = "Take this file to the Moth and you will be Rewarded.";
					GameEngine.wormDialogue.y = y - 25;					
				}
				if (state == 2) {
					GameEngine.wormDialogue.theText.text = "Vive la Résistance!";
					GameEngine.wormDialogue.y = y - 25;
				}
				GameEngine.wormDialogue.x = (x +8) - (GameEngine.wormDialogue.theText.width / 2);
				GameEngine.wormDialogue.visible = true;
			}else {
				GameEngine.wormDialogue.visible = false
			}
		}		
	}

}